<template>
  <el-drawer v-model="drawerVisible" title="搜索" direction="rtl" size="350px">
    <template #header>
      <span class="text-16px font-700">搜索</span>
    </template>
    <div class="search-drawer" style="height: 100%">
      <el-form
        ref="queryFormRef"
        :inline="true"
        :model="queryParams"
        class="-mb-15px"
        label-width="68px"
      >
        <el-form-item label="项目编码" prop="projectNo">
          <el-input
            v-model="queryParams.projectNo"
            placeholder="请输入项目编码"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="线路编码" prop="lineCode">
          <el-input
            v-model="queryParams.lineCode"
            placeholder="请输入线路编码"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="线路名称" prop="lineName">
          <el-input
            v-model="queryParams.lineName"
            placeholder="请输入线路名称"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="线路类别(公路运输、铁路运输)" prop="lineType">
          <el-select
            v-model="queryParams.lineType"
            placeholder="请选择线路类别(公路运输、铁路运输)"
            clearable
            class="!w-240px"
          >
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="客户统一信用代码" prop="customerUscc">
          <el-input
            v-model="queryParams.customerUscc"
            placeholder="请输入客户统一信用代码"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="客户类型" prop="customerType">
          <el-select
            v-model="queryParams.customerType"
            placeholder="请选择客户类型"
            clearable
            class="!w-240px"
          >
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="客户名称" prop="customerName">
          <el-input
            v-model="queryParams.customerName"
            placeholder="请输入客户名称"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="发货单位名称" prop="consignor">
          <el-input
            v-model="queryParams.consignor"
            placeholder="请输入发货单位名称"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="发货单位统一社会信用代码" prop="consignorUscc">
          <el-input
            v-model="queryParams.consignorUscc"
            placeholder="请输入发货单位统一社会信用代码"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="发货联系人" prop="consignorName">
          <el-input
            v-model="queryParams.consignorName"
            placeholder="请输入发货联系人"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="发货联系人电话" prop="consignorPhone">
          <el-input
            v-model="queryParams.consignorPhone"
            placeholder="请输入发货联系人电话"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="发货地区划代码" prop="consignorAddrCode">
          <el-input
            v-model="queryParams.consignorAddrCode"
            placeholder="请输入发货地区划代码"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="出发(装货)地址" prop="consignorAddr">
          <el-input
            v-model="queryParams.consignorAddr"
            placeholder="请输入出发(装货)地址"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="发货方详细地址" prop="consignorDetailAddr">
          <el-input
            v-model="queryParams.consignorDetailAddr"
            placeholder="请输入发货方详细地址"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="收货单位名称" prop="consignee">
          <el-input
            v-model="queryParams.consignee"
            placeholder="请输入收货单位名称"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="收货单位统一社会信用代码" prop="consigneeUscc">
          <el-input
            v-model="queryParams.consigneeUscc"
            placeholder="请输入收货单位统一社会信用代码"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="收货联系人" prop="consigneeName">
          <el-input
            v-model="queryParams.consigneeName"
            placeholder="请输入收货联系人"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="收货联系人电话" prop="consigneePhone">
          <el-input
            v-model="queryParams.consigneePhone"
            placeholder="请输入收货联系人电话"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="收货地区划代码" prop="consigneeAddrCode">
          <el-input
            v-model="queryParams.consigneeAddrCode"
            placeholder="请输入收货地区划代码"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="目的(收货)地址" prop="consigneeAddr">
          <el-input
            v-model="queryParams.consigneeAddr"
            placeholder="请输入目的(收货)地址"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="收货方详细地址" prop="consigneeDetailAddr">
          <el-input
            v-model="queryParams.consigneeDetailAddr"
            placeholder="请输入收货方详细地址"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="货物名称" prop="goodsName">
          <el-input
            v-model="queryParams.goodsName"
            placeholder="请输入货物名称"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="创建时间" prop="createTime">
          <el-date-picker
            v-model="queryParams.createTime"
            value-format="YYYY-MM-DD HH:mm:ss"
            type="daterange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
            class="!w-220px"
          />
        </el-form-item>
        <el-form-item label="机构ID" prop="deptId">
          <el-input
            v-model="queryParams.deptId"
            placeholder="请输入机构ID"
            clearable
            class="!w-240px"
          />
        </el-form-item>
      </el-form>
    </div>
    <template #footer>
      <div style="flex: auto">
        <el-button @click="reset">重置</el-button>
        <el-button type="primary" @click="search">搜索</el-button>
      </div>
    </template>
  </el-drawer>
</template>

<script setup lang="ts">
  import { computed, ref } from 'vue'

  // 定义 props 和 emits
  const props = defineProps({
    modelValue: {
      type: Object,
      required: true,
    }
  });

  const emit = defineEmits(['update:modelValue', 'search', 'reset']);

  // 控制抽屉显示
  const drawerVisible = ref(false);

  // 使用 computed 实现双向绑定
  const queryParams = computed({
    get: () => props.modelValue,
    set: (value) => emit('update:modelValue', value)
  });

  // 打开抽屉
  function open() {
    drawerVisible.value = true;
  }

  // 关闭抽屉
  function close() {
    drawerVisible.value = false;
  }

  // 搜索
  function search() {
    close();
    emit('search', queryParams.value);
  }

  const queryFormRef = ref()
  // 重置
  function reset() {
    queryFormRef.value.resetFields()
    emit('reset', queryParams.value);
  }

  // 暴露 open 方法
  defineExpose({
    open
  });
</script>

<style lang="scss" scoped>
  .search-drawer {
    ::v-deep {
      .el-form {
        height: 98%;
      }
    }
  }
</style>
